<?php
namespace SSO\Controller;
use Think\Controller;

class CommonController extends Controller {

    //Webservice 主机
    private $server;

    public function _initialize(){
        $this->server = C('SSO_SERVER');
    }

    /**
     * 通过Token获取用户信息
     *
     * @param $token
     */
    public function getUserByToken($token){
        return $this->_verifyToken($token);
    }

    /**
     * 清除Token
     *
     * @param $token
     */
    public function clearSSOToken($token){
        $client = $this->_soap();
        $data['tokenValue'] = $token;
        $result =$client->ClearToken($data);
        return $result->ClearTokenResult;
    }


    /**
     * 验证Token
     *
     * @param $token
     */
    private function _verifyToken($token){
        $client = $this->_soap();
        $data['tokenValue'] = $token;
        $result =$client->TokenGetCredence($data);
        $user = $result->TokenGetCredenceResult->enc_value;
        return $user;
    }


    /**
     * WebService
     *
     * @return \SoapClient
     */
    private function _soap(){
        header('Content-Type: text/html; charset=utf-8');
        $s = new \SoapClient($this->server.'/ssoservice/webservice/gateway.asmx?wsdl');
        $u = new \SoapHeader('http://tempuri.org/','SSOSoapHeader',array('UserName'=>'admin','PassWord'=>'NnYZe7oD81Kd8QRS4tUMze'),true);
        $s->__setSoapHeaders($u);
        return  $s;
    }
}